package com.learn.easy;

/**
 * <p>
 *Given an integer num, return a string of its base 7 representation.
 *
 * Example 1:
 *
 * Input: num = 100
 * Output: "202"
 * Example 2:
 *
 * Input: num = -7
 * Output: "-10"
 * </p>
 *
 * @author guapi
 * @date 2023-11-08
 */
public class num_504 {
    public static void main(String[] args) {
        System.out.println(convertToBase7(10));
    }
    public static String convertToBase7(int num) {
        boolean b = num < 0;
        if (b) {
            num=-num;
        }
        StringBuilder sb = new StringBuilder();
        do {
            sb.append(num % 7);
            num /= 7;
        } while (num != 0);
        sb.reverse();
        return b ? "-" + sb.toString() : sb.toString();

    }
}
